<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>第十五章：memcached教程 | Flask进阶课程课件</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="gitbook/style.css">
    
        
        <link rel="stylesheet" href="gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="./di-shi-sizhang-ff1a-redis-jiao-cheng.html" />
    
    
    <link rel="prev" href="./di-shi-si-zhang-ff1a-flask/di-er-jie-ff1a-flask-restful-cha-jian.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="15"
        data-chapter-title="第十五章：memcached教程"
        data-filepath="di-shi-er-zhang-ff1a-memcached-jiao-cheng.md"
        data-basepath="."
        data-revision="Tue Aug 14 2018 17:50:50 GMT+0800 (中国标准时间)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="./index.html">
                
                        <i class="fa fa-check"></i>
                        
                        Introduction
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="chapter1.html">
            
                
                    <a href="./chapter1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        第一章：学前准备
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="chapter1/di-yi-jie-ff1a-xu-ni-huan-jing.html">
            
                
                    <a href="./chapter1/di-yi-jie-ff1a-xu-ni-huan-jing.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        第一节：虚拟环境
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="di-er-zhang-ff1a-ren-shi-web.html">
            
                
                    <a href="./di-er-zhang-ff1a-ren-shi-web.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        第二章：认识web
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3" data-path="di-san-zhang-ff1a-flask-ru-men-2014-2014-url.html">
            
                
                    <a href="./di-san-zhang-ff1a-flask-ru-men-2014-2014-url.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        第三章：URL与视图
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="di-san-zhang-ff1a-flask-ru-men-2014-2014-url/di-yi-jie-ff1a-di-yi-ge-flask-cheng-xu.html">
            
                
                    <a href="./di-san-zhang-ff1a-flask-ru-men-2014-2014-url/di-yi-jie-ff1a-di-yi-ge-flask-cheng-xu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        第一节：Flask简介
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="di-san-zhang-ff1a-flask-ru-men-2014-2014-url/di-er-jie-ff1a-xiang-mu-pei-zhi.html">
            
                
                    <a href="./di-san-zhang-ff1a-flask-ru-men-2014-2014-url/di-er-jie-ff1a-xiang-mu-pei-zhi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        第二节：项目配置
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="di-san-zhang-ff1a-flask-ru-men-2014-2014-url/di-san-jie-ff1a-url-yu-shi-tu-han-shu.html">
            
                
                    <a href="./di-san-zhang-ff1a-flask-ru-men-2014-2014-url/di-san-jie-ff1a-url-yu-shi-tu-han-shu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        第三节：URL与视图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="di-san-zhang-ff1a-flask-ru-men-2014-2014-url/di-si-jie-ff1a-guan-yu-xiang-ying.html">
            
                
                    <a href="./di-san-zhang-ff1a-flask-ru-men-2014-2014-url/di-si-jie-ff1a-guan-yu-xiang-ying.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        第四节：关于响应
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09.html">
            
                
                    <a href="./di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        第四章：模版
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-yi-jie-ff1a-mo-ban-jian-jie.html">
            
                
                    <a href="./di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-yi-jie-ff1a-mo-ban-jian-jie.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        第一节：模版简介
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-er-jie-ff1a-jinja2-mo-ban-gai-shu.html">
            
                
                    <a href="./di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-er-jie-ff1a-jinja2-mo-ban-gai-shu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        第二节：Jinja2模版概述
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-san-jie-ff1a-jinja2-guo-lv-qi.html">
            
                
                    <a href="./di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-san-jie-ff1a-jinja2-guo-lv-qi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        第三节：过滤器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-si-jie-ff1a-jinja2-mo-ban-kong-zhi-yu-ju.html">
            
                
                    <a href="./di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-si-jie-ff1a-jinja2-mo-ban-kong-zhi-yu-ju.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        第四节：控制语句
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-wu-jie-ff1a-jinja2-mo-ban-ce-shi-qi.html">
            
                
                    <a href="./di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-wu-jie-ff1a-jinja2-mo-ban-ce-shi-qi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        第五节：测试器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-liu-jie-ff1a-hong-he-import-yu-ju.html">
            
                
                    <a href="./di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-liu-jie-ff1a-hong-he-import-yu-ju.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.6.</b>
                        
                        第六节：宏和import语句
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-qijie-ff1a-include-he-set-yu-ju.html">
            
                
                    <a href="./di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-qijie-ff1a-include-he-set-yu-ju.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.7.</b>
                        
                        第七节：include和set语句
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.8" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-ba-jie-ff1a-mo-ban-ji-cheng.html">
            
                
                    <a href="./di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-ba-jie-ff1a-mo-ban-ji-cheng.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.8.</b>
                        
                        第八节：模版继承
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-jiu-jie-ff1a-zhuan-yi.html">
            
                
                    <a href="./di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-jiu-jie-ff1a-zhuan-yi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.</b>
                        
                        第九节：转义
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.10" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-shi-jie-ff1a-shu-ju-lei-xing-he-yun-suan-fu.html">
            
                
                    <a href="./di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-shi-jie-ff1a-shu-ju-lei-xing-he-yun-suan-fu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.10.</b>
                        
                        第十节：数据类型和运算符
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.11" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-shi-yi-jie-ff1a-jing-tai-wen-jian-de-pei-zhi.html">
            
                
                    <a href="./di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-shi-yi-jie-ff1a-jing-tai-wen-jian-de-pei-zhi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.11.</b>
                        
                        第十一节：静态文件的配置
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="di-wu-zhang-ff1a-shi-tu-gao-ji.html">
            
                
                    <a href="./di-wu-zhang-ff1a-shi-tu-gao-ji.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        第五章：视图高级
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="di-wu-zhang-ff1a-shi-tu-gao-ji/di-yi-jie-ff1a-lei-shi-tu.html">
            
                
                    <a href="./di-wu-zhang-ff1a-shi-tu-gao-ji/di-yi-jie-ff1a-lei-shi-tu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        第一节：类视图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="di-wu-zhang-ff1a-shi-tu-gao-ji/di-er-jie-ff1a-lan-tu.html">
            
                
                    <a href="./di-wu-zhang-ff1a-shi-tu-gao-ji/di-er-jie-ff1a-lan-tu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        第二节：蓝图和子域名
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku.html">
            
                
                    <a href="./di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        第六章：SQLAlchemy数据库
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-yi-jie-ff1a-mysql-shu-ju-ku-de-an-zhuang.html">
            
                
                    <a href="./di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-yi-jie-ff1a-mysql-shu-ju-ku-de-an-zhuang.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        第一节：MySQL数据库的安装
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-yi-jie-ff1a-sqlalchemy-jie-shao-he-ji-ben-shi-yong.html">
            
                
                    <a href="./di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-yi-jie-ff1a-sqlalchemy-jie-shao-he-ji-ben-shi-yong.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        第二节：SQLAlchemy介绍和基本使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-san-jie-ff1a-sqlalchemy-de-orm.html">
            
                
                    <a href="./di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-san-jie-ff1a-sqlalchemy-de-orm.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        第三节：SQLAlchemy的ORM（1）
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-si-jie-ff1a-sqlalchemy-de-orm-2.html">
            
                
                    <a href="./di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-si-jie-ff1a-sqlalchemy-de-orm-2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        第四节：SQLAlchemy的ORM（2）
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.5" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-wu-jie-ff1a-sqlalchemy-de-orm-3.html">
            
                
                    <a href="./di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-wu-jie-ff1a-sqlalchemy-de-orm-3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.5.</b>
                        
                        第五节：SQLAlchemy的ORM（3）
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.6" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-liu-jie-ff1a-sqlalchemy-de-orm-4.html">
            
                
                    <a href="./di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-liu-jie-ff1a-sqlalchemy-de-orm-4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.6.</b>
                        
                        第六节：SQLAlchemy的ORM（4）
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.7" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-qi-jie-ff1a-sqlalchemy-de-orm-5.html">
            
                
                    <a href="./di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-qi-jie-ff1a-sqlalchemy-de-orm-5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.7.</b>
                        
                        第七节：SQLAlchemy的ORM（5）
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.8" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-si-jie-ff1aflask-sqlalchemy.html">
            
                
                    <a href="./di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-si-jie-ff1aflask-sqlalchemy.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.8.</b>
                        
                        第八节：Flask-SQLAlchemy
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" data-path="di-qi-zhang-ff1a-flask-script.html">
            
                
                    <a href="./di-qi-zhang-ff1a-flask-script.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        第七章：Flask-Script
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8" data-path="di-bazhang-ff1a-alembic-jiao-cheng.html">
            
                
                    <a href="./di-bazhang-ff1a-alembic-jiao-cheng.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        第八章：alembic教程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9" data-path="di-ba-zhang-ff1a-flask-migrate.html">
            
                
                    <a href="./di-ba-zhang-ff1a-flask-migrate.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.</b>
                        
                        第九章：Flask-Migrate
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10" data-path="di-jiu-zhang-ff1a-flask-wtf.html">
            
                
                    <a href="./di-jiu-zhang-ff1a-flask-wtf.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.</b>
                        
                        第十章：Flask-WTF
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="11" data-path="di-shi-yi-zhang-ff1a-cookie-he-session.html">
            
                
                    <a href="./di-shi-yi-zhang-ff1a-cookie-he-session.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.</b>
                        
                        第十一章：cookie和session
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12" data-path="di-shi-zhang-ff1a-shang-xia-wen.html">
            
                
                    <a href="./di-shi-zhang-ff1a-shang-xia-wen.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.</b>
                        
                        第十二章：Flask上下文
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="13" data-path="di-shi-yi-zhang-ff1a-flask-xin-hao-ji-zhi.html">
            
                
                    <a href="./di-shi-yi-zhang-ff1a-flask-xin-hao-ji-zhi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>13.</b>
                        
                        第十三章：Flask信号机制
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="14" data-path="di-shi-si-zhang-ff1a-flask.html">
            
                
                    <a href="./di-shi-si-zhang-ff1a-flask.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>14.</b>
                        
                        第十四章：Flask-Restful
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="14.1" data-path="di-shi-si-zhang-ff1a-flask/di-yi-jie-ff1a-restful-api-gui-fan.html">
            
                
                    <a href="./di-shi-si-zhang-ff1a-flask/di-yi-jie-ff1a-restful-api-gui-fan.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>14.1.</b>
                        
                        第一节：Restful API规范
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="14.2" data-path="di-shi-si-zhang-ff1a-flask/di-er-jie-ff1a-flask-restful-cha-jian.html">
            
                
                    <a href="./di-shi-si-zhang-ff1a-flask/di-er-jie-ff1a-flask-restful-cha-jian.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>14.2.</b>
                        
                        第二节：Flask-Restful插件
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter active" data-level="15" data-path="di-shi-er-zhang-ff1a-memcached-jiao-cheng.html">
            
                
                    <a href="./di-shi-er-zhang-ff1a-memcached-jiao-cheng.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>15.</b>
                        
                        第十五章：memcached教程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="16" data-path="di-shi-sizhang-ff1a-redis-jiao-cheng.html">
            
                
                    <a href="./di-shi-sizhang-ff1a-redis-jiao-cheng.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>16.</b>
                        
                        第十六章：redis教程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="17" data-path="di-shi-liu-zhang-ff1a-csrf-gong-ji.html">
            
                
                    <a href="./di-shi-liu-zhang-ff1a-csrf-gong-ji.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>17.</b>
                        
                        第十七章：CSRF攻击
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="18" data-path="di-shi-ba-zhang-ff1a-qi-niu-yun-pei-zhi.html">
            
                
                    <a href="./di-shi-ba-zhang-ff1a-qi-niu-yun-pei-zhi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>18.</b>
                        
                        第十八章：七牛云配置
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="19" data-path="di-shi-jiu-zhang-ff1a-bu-shu-flask-xiang-mu.html">
            
                
                    <a href="./di-shi-jiu-zhang-ff1a-bu-shu-flask-xiang-mu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>19.</b>
                        
                        第十九章：部署Flask项目
                    </a>
            
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="./" >Flask进阶课程课件</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="memcached">memcached</h1>
<h3 id="&#x4EC0;&#x4E48;&#x662F;memcached&#xFF1A;">&#x4EC0;&#x4E48;&#x662F;memcached&#xFF1A;</h3>
<ol>
<li><code>memcached</code>&#x4E4B;&#x524D;&#x662F;<code>danga</code>&#x7684;&#x4E00;&#x4E2A;&#x9879;&#x76EE;&#xFF0C;&#x6700;&#x65E9;&#x662F;&#x4E3A;LiveJournal&#x670D;&#x52A1;&#x7684;&#xFF0C;&#x5F53;&#x521D;&#x8BBE;&#x8BA1;&#x5E08;&#x4E3A;&#x4E86;&#x52A0;&#x901F;LiveJournal&#x8BBF;&#x95EE;&#x901F;&#x5EA6;&#x800C;&#x5F00;&#x53D1;&#x7684;&#xFF0C;&#x540E;&#x6765;&#x88AB;&#x5F88;&#x591A;&#x5927;&#x578B;&#x9879;&#x76EE;&#x91C7;&#x7528;&#x3002;&#x5B98;&#x7F51;&#x662F;<code>www.danga.com</code>&#x6216;&#x8005;&#x662F;<code>memcached.org</code>&#x3002;</li>
<li><code>Memcached</code>&#x662F;&#x4E00;&#x4E2A;&#x9AD8;&#x6027;&#x80FD;&#x7684;<strong>&#x5206;&#x5E03;&#x5F0F;</strong>&#x7684;<strong>&#x5185;&#x5B58;&#x5BF9;&#x8C61;&#x7F13;&#x5B58;</strong>&#x7CFB;&#x7EDF;&#xFF0C;&#x5168;&#x4E16;&#x754C;&#x6709;&#x4E0D;&#x5C11;&#x516C;&#x53F8;&#x91C7;&#x7528;&#x8FD9;&#x4E2A;&#x7F13;&#x5B58;&#x9879;&#x76EE;&#x6765;&#x6784;&#x5EFA;&#x5927;&#x8D1F;&#x8F7D;&#x7684;&#x7F51;&#x7AD9;&#xFF0C;&#x6765;&#x5206;&#x62C5;&#x6570;&#x636E;&#x5E93;&#x7684;&#x538B;&#x529B;&#x3002;<code>Memcached</code>&#x662F;&#x901A;&#x8FC7;&#x5728;&#x5185;&#x5B58;&#x91CC;&#x7EF4;&#x62A4;&#x4E00;&#x4E2A;&#x7EDF;&#x4E00;&#x7684;&#x5DE8;&#x5927;&#x7684;hash&#x8868;&#xFF0C;<code>memcached</code>&#x80FD;&#x5B58;&#x50A8;&#x5404;&#x79CD;&#x5404;&#x6837;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x5305;&#x62EC;&#x56FE;&#x50CF;&#x3001;&#x89C6;&#x9891;&#x3001;&#x6587;&#x4EF6;&#x3001;&#x4EE5;&#x53CA;&#x6570;&#x636E;&#x5E93;&#x68C0;&#x7D22;&#x7684;&#x7ED3;&#x679C;&#x7B49;&#x3002;&#x7B80;&#x5355;&#x7684;&#x8BF4;&#x5C31;&#x662F;&#x5C06;&#x6570;&#x636E;&#x8C03;&#x7528;&#x5230;&#x5185;&#x5B58;&#x4E2D;&#xFF0C;&#x7136;&#x540E;&#x4ECE;&#x5185;&#x5B58;&#x4E2D;&#x8BFB;&#x53D6;&#xFF0C;&#x4ECE;&#x800C;&#x5927;&#x5927;&#x63D0;&#x9AD8;&#x8BFB;&#x53D6;&#x901F;&#x5EA6;&#x3002;</li>
<li>&#x54EA;&#x4E9B;&#x60C5;&#x51B5;&#x4E0B;&#x9002;&#x5408;&#x4F7F;&#x7528;<code>Memcached</code>&#xFF1A;&#x5B58;&#x50A8;&#x9A8C;&#x8BC1;&#x7801;&#xFF08;&#x56FE;&#x5F62;&#x9A8C;&#x8BC1;&#x7801;&#x3001;&#x77ED;&#x4FE1;&#x9A8C;&#x8BC1;&#x7801;&#xFF09;&#x3001;&#x767B;&#x5F55;session&#x7B49;&#x6240;&#x6709;&#x4E0D;&#x662F;&#x81F3;&#x5173;&#x91CD;&#x8981;&#x7684;&#x6570;&#x636E;&#x3002;</li>
</ol>
<h3 id="&#x5B89;&#x88C5;&#x548C;&#x542F;&#x52A8;memcached&#xFF1A;">&#x5B89;&#x88C5;&#x548C;&#x542F;&#x52A8;<code>memcached</code>&#xFF1A;</h3>
<ol>
<li>windows&#xFF1A;<ul>
<li>&#x5B89;&#x88C5;&#xFF1A;<code>memcached.exe -d install</code>&#x3002;</li>
<li>&#x542F;&#x52A8;&#xFF1A;<code>memcached.exe -d start</code>&#x3002;</li>
</ul>
</li>
<li><p>linux&#xFF08;ubuntu&#xFF09;&#xFF1A;</p>
<ul>
<li><p>&#x5B89;&#x88C5;&#xFF1A;<code>sudo apt install memcached</code></p>
</li>
<li><p>&#x542F;&#x52A8;&#xFF1A;</p>
<pre><code class="lang-python">cd /usr/local/memcached/bin
./memcached -d start
</code></pre>
</li>
</ul>
</li>
<li><p>&#x53EF;&#x80FD;&#x51FA;&#x73B0;&#x7684;&#x95EE;&#x9898;&#xFF1A;</p>
<ul>
<li>&#x63D0;&#x793A;&#x4F60;&#x6CA1;&#x6709;&#x6743;&#x9650;&#xFF1A;&#x5728;&#x6253;&#x5F00;cmd&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x53F3;&#x952E;&#x4F7F;&#x7528;&#x7BA1;&#x7406;&#x5458;&#x8EAB;&#x4EFD;&#x8FD0;&#x884C;&#x3002;</li>
<li>&#x63D0;&#x793A;&#x7F3A;&#x5C11;<code>pthreadGC2.dll</code>&#x6587;&#x4EF6;&#xFF1A;&#x5C06;<code>pthreadGC2.dll</code>&#x6587;&#x4EF6;&#x62F7;&#x8D1D;&#x5230;<code>windows/System32</code>.</li>
<li>&#x4E0D;&#x8981;&#x653E;&#x5728;&#x542B;&#x6709;&#x4E2D;&#x6587;&#x7684;&#x8DEF;&#x5F84;&#x4E0B;&#x9762;&#x3002;</li>
</ul>
</li>
<li><p>&#x542F;&#x52A8;<code>memcached</code>&#xFF1A;</p>
<ul>
<li><code>-d</code>&#xFF1A;&#x8FD9;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x8BA9;<code>memcached</code>&#x5728;&#x540E;&#x53F0;&#x8FD0;&#x884C;&#x3002;</li>
<li><code>-m</code>&#xFF1A;&#x6307;&#x5B9A;&#x5360;&#x7528;&#x591A;&#x5C11;&#x5185;&#x5B58;&#x3002;&#x4EE5;<code>M</code>&#x4E3A;&#x5355;&#x4F4D;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;<code>64M</code>&#x3002;</li>
<li><code>-p</code>&#xFF1A;&#x6307;&#x5B9A;&#x5360;&#x7528;&#x7684;&#x7AEF;&#x53E3;&#x3002;&#x9ED8;&#x8BA4;&#x7AEF;&#x53E3;&#x662F;<code>11211</code>&#x3002;</li>
<li><code>-l</code>&#xFF1A;&#x522B;&#x7684;&#x673A;&#x5668;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x54EA;&#x4E2A;ip&#x5730;&#x5740;&#x8FDE;&#x63A5;&#x5230;&#x6211;&#x8FD9;&#x53F0;&#x670D;&#x52A1;&#x5668;&#x3002;&#x5982;&#x679C;&#x662F;&#x901A;&#x8FC7;<code>service memcached start</code>&#x7684;&#x65B9;&#x5F0F;&#xFF0C;&#x90A3;&#x4E48;&#x53EA;&#x80FD;&#x901A;&#x8FC7;&#x672C;&#x673A;&#x8FDE;&#x63A5;&#x3002;&#x5982;&#x679C;&#x60F3;&#x8981;&#x8BA9;&#x522B;&#x7684;&#x673A;&#x5668;&#x8FDE;&#x63A5;&#xFF0C;&#x5C31;&#x5FC5;&#x987B;&#x8BBE;&#x7F6E;<code>-l 0.0.0.0</code>&#x3002;</li>
</ul>
<p>&#x5982;&#x679C;&#x60F3;&#x8981;&#x4F7F;&#x7528;&#x4EE5;&#x4E0A;&#x53C2;&#x6570;&#x6765;&#x6307;&#x5B9A;&#x4E00;&#x4E9B;&#x914D;&#x7F6E;&#x4FE1;&#x606F;&#xFF0C;&#x90A3;&#x4E48;&#x4E0D;&#x80FD;&#x4F7F;&#x7528;<code>service memcached start</code>&#xFF0C;&#x800C;&#x5E94;&#x8BE5;&#x4F7F;&#x7528;<code>/usr/bin/memcached</code>&#x7684;&#x65B9;&#x5F0F;&#x6765;&#x8FD0;&#x884C;&#x3002;&#x6BD4;&#x5982;<code>/usr/bin/memcached -u memcache -m 1024 -p 11222 start</code>&#x3002;</p>
</li>
</ol>
<h3 id="telnet&#x64CD;&#x4F5C;memcached&#xFF1A;"><code>telnet</code>&#x64CD;&#x4F5C;<code>memcached</code>&#xFF1A;</h3>
<p><code>telnet ip&#x5730;&#x5740; [11211]</code></p>
<ol>
<li><p>&#x6DFB;&#x52A0;&#x6570;&#x636E;&#xFF1A;</p>
<ul>
<li><code>set</code>&#xFF1A;<ul>
<li>&#x8BED;&#x6CD5;&#xFF1A;<pre><code class="lang-python">  set key flas(&#x662F;&#x5426;&#x538B;&#x7F29;) timeout value_length
  value
</code></pre>
</li>
<li>&#x793A;&#x4F8B;&#xFF1A;<pre><code class="lang-python">  set username <span class="hljs-number">0</span> <span class="hljs-number">60</span> <span class="hljs-number">7</span>
  zhiliao
</code></pre>
</li>
</ul>
</li>
<li><p><code>add</code>&#xFF1A;</p>
<ul>
<li>&#x8BED;&#x6CD5;&#xFF1A;<pre><code class="lang-python">  add key flas(<span class="hljs-number">0</span>) timeout value_length
  value
</code></pre>
</li>
<li><p>&#x793A;&#x4F8B;&#xFF1A;</p>
<pre><code class="lang-python">  add username <span class="hljs-number">0</span> <span class="hljs-number">60</span> <span class="hljs-number">7</span>
  xiaotuo
</code></pre>
<p><code>set</code>&#x548C;<code>add</code>&#x7684;&#x533A;&#x522B;&#xFF1A;<code>add</code>&#x662F;&#x53EA;&#x8D1F;&#x8D23;&#x6DFB;&#x52A0;&#x6570;&#x636E;&#xFF0C;&#x4E0D;&#x4F1A;&#x53BB;&#x4FEE;&#x6539;&#x6570;&#x636E;&#x3002;&#x5982;&#x679C;&#x6DFB;&#x52A0;&#x7684;&#x6570;&#x636E;&#x7684;<code>key</code>&#x5DF2;&#x7ECF;&#x5B58;&#x5728;&#x4E86;&#xFF0C;&#x5219;&#x6DFB;&#x52A0;&#x5931;&#x8D25;&#xFF0C;&#x5982;&#x679C;&#x6DFB;&#x52A0;&#x7684;<code>key</code>&#x4E0D;&#x5B58;&#x5728;&#xFF0C;&#x5219;&#x6DFB;&#x52A0;&#x6210;&#x529F;&#x3002;&#x800C;<code>set</code>&#x4E0D;&#x540C;&#xFF0C;&#x5982;&#x679C;<code>memcached</code>&#x4E2D;&#x4E0D;&#x5B58;&#x5728;&#x76F8;&#x540C;&#x7684;<code>key</code>&#xFF0C;&#x5219;&#x8FDB;&#x884C;&#x6DFB;&#x52A0;&#xFF0C;&#x5982;&#x679C;&#x5B58;&#x5728;&#xFF0C;&#x5219;&#x66FF;&#x6362;&#x3002;</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p>&#x83B7;&#x53D6;&#x6570;&#x636E;&#xFF1A;</p>
<ul>
<li>&#x8BED;&#x6CD5;&#xFF1A;<pre><code class="lang-python">  get key
</code></pre>
</li>
<li>&#x793A;&#x4F8B;&#xFF1A;<pre><code class="lang-python">  get username
</code></pre>
</li>
</ul>
</li>
<li><p>&#x5220;&#x9664;&#x6570;&#x636E;&#xFF1A;</p>
<ul>
<li>&#x8BED;&#x6CD5;&#xFF1A;<pre><code class="lang-python">  delete key
</code></pre>
</li>
<li>&#x793A;&#x4F8B;&#xFF1A;<pre><code class="lang-python">  delete username
</code></pre>
</li>
<li><code>flush_all</code>&#xFF1A;&#x5220;&#x9664;<code>memcached</code>&#x4E2D;&#x7684;&#x6240;&#x6709;&#x6570;&#x636E;&#x3002;</li>
</ul>
</li>
<li><p>&#x67E5;&#x770B;<code>memcached</code>&#x7684;&#x5F53;&#x524D;&#x72B6;&#x6001;&#xFF1A;</p>
<ul>
<li>&#x8BED;&#x6CD5;&#xFF1A;<code>stats</code>&#x3002;</li>
</ul>
</li>
</ol>
<h3 id="&#x901A;&#x8FC7;python&#x64CD;&#x4F5C;memcached&#xFF1A;">&#x901A;&#x8FC7;<code>python</code>&#x64CD;&#x4F5C;<code>memcached</code>&#xFF1A;</h3>
<ol>
<li>&#x5B89;&#x88C5;&#xFF1A;<code>python-memcached</code>&#xFF1A;<code>pip install python-memcached</code>&#x3002;</li>
<li><p>&#x5EFA;&#x7ACB;&#x8FDE;&#x63A5;&#xFF1A;</p>
<pre><code class="lang-python"> <span class="hljs-keyword">import</span> memcache
 mc = memcache.Client([<span class="hljs-string">&apos;127.0.0.1:11211&apos;</span>,<span class="hljs-string">&apos;192.168.174.130:11211&apos;</span>],debug=<span class="hljs-keyword">True</span>)
</code></pre>
</li>
<li><p>&#x8BBE;&#x7F6E;&#x6570;&#x636E;&#xFF1A;</p>
<pre><code class="lang-python"> mc.set(<span class="hljs-string">&apos;username&apos;</span>,<span class="hljs-string">&apos;hello world&apos;</span>,time=<span class="hljs-number">60</span>*<span class="hljs-number">5</span>)
 mc.set_multi({<span class="hljs-string">&apos;email&apos;</span>:<span class="hljs-string">&apos;xxx@qq.com&apos;</span>,<span class="hljs-string">&apos;telphone&apos;</span>:<span class="hljs-string">&apos;111111&apos;</span>},time=<span class="hljs-number">60</span>*<span class="hljs-number">5</span>)
</code></pre>
</li>
<li><p>&#x83B7;&#x53D6;&#x6570;&#x636E;&#xFF1A;</p>
<pre><code class="lang-python"> mc.get(<span class="hljs-string">&apos;telphone&apos;</span>)
</code></pre>
</li>
<li><p>&#x5220;&#x9664;&#x6570;&#x636E;&#xFF1A;</p>
<pre><code class="lang-python"> mc.delete(<span class="hljs-string">&apos;email&apos;</span>)
</code></pre>
</li>
<li><p>&#x81EA;&#x589E;&#x957F;&#xFF1A;</p>
<pre><code class="lang-python"> mc.incr(<span class="hljs-string">&apos;read_count&apos;</span>)
</code></pre>
</li>
<li><p>&#x81EA;&#x51CF;&#x5C11;&#xFF1A;</p>
<pre><code class="lang-python"> mc.decr(<span class="hljs-string">&apos;read_count&apos;</span>)
</code></pre>
</li>
</ol>
<h3 id="memcached&#x7684;&#x5B89;&#x5168;&#x6027;&#xFF1A;">memcached&#x7684;&#x5B89;&#x5168;&#x6027;&#xFF1A;</h3>
<p><code>memcached</code>&#x7684;&#x64CD;&#x4F5C;&#x4E0D;&#x9700;&#x8981;&#x4EFB;&#x4F55;&#x7528;&#x6237;&#x540D;&#x548C;&#x5BC6;&#x7801;&#xFF0C;&#x53EA;&#x9700;&#x8981;&#x77E5;&#x9053;<code>memcached</code>&#x670D;&#x52A1;&#x5668;&#x7684;ip&#x5730;&#x5740;&#x548C;&#x7AEF;&#x53E3;&#x53F7;&#x5373;&#x53EF;&#x3002;&#x56E0;&#x6B64;<code>memcached</code>&#x4F7F;&#x7528;&#x7684;&#x65F6;&#x5019;&#x5C24;&#x5176;&#x8981;&#x6CE8;&#x610F;&#x4ED6;&#x7684;&#x5B89;&#x5168;&#x6027;&#x3002;&#x8FD9;&#x91CC;&#x63D0;&#x4F9B;&#x4E24;&#x79CD;&#x5B89;&#x5168;&#x7684;&#x89E3;&#x51B3;&#x65B9;&#x6848;&#x3002;&#x5206;&#x522B;&#x6765;&#x8FDB;&#x884C;&#x8BB2;&#x89E3;&#xFF1A;  </p>
<ol>
<li>&#x4F7F;&#x7528;<code>-l</code>&#x53C2;&#x6570;&#x8BBE;&#x7F6E;&#x4E3A;&#x53EA;&#x6709;&#x672C;&#x5730;&#x53EF;&#x4EE5;&#x8FDE;&#x63A5;&#xFF1A;&#x8FD9;&#x79CD;&#x65B9;&#x5F0F;&#xFF0C;&#x5C31;&#x53EA;&#x80FD;&#x901A;&#x8FC7;&#x672C;&#x673A;&#x624D;&#x80FD;&#x8FDE;&#x63A5;&#xFF0C;&#x522B;&#x7684;&#x673A;&#x5668;&#x90FD;&#x4E0D;&#x80FD;&#x8BBF;&#x95EE;&#xFF0C;&#x53EF;&#x4EE5;&#x8FBE;&#x5230;&#x6700;&#x597D;&#x7684;&#x5B89;&#x5168;&#x6027;&#x3002;  </li>
<li>&#x4F7F;&#x7528;&#x9632;&#x706B;&#x5899;&#xFF0C;&#x5173;&#x95ED;<code>11211</code>&#x7AEF;&#x53E3;&#xFF0C;&#x5916;&#x9762;&#x4E5F;&#x4E0D;&#x80FD;&#x8BBF;&#x95EE;&#x3002;</li>
</ol>
<pre><code class="lang-shell">  ufw enable # &#x5F00;&#x542F;&#x9632;&#x706B;&#x5899;
  ufw disable # &#x5173;&#x95ED;&#x9632;&#x706B;&#x5899;
  ufw default deny # &#x9632;&#x706B;&#x5899;&#x4EE5;&#x7981;&#x6B62;&#x7684;&#x65B9;&#x5F0F;&#x6253;&#x5F00;&#xFF0C;&#x9ED8;&#x8BA4;&#x662F;&#x5173;&#x95ED;&#x90A3;&#x4E9B;&#x6CA1;&#x6709;&#x5F00;&#x542F;&#x7684;&#x7AEF;&#x53E3;
  ufw deny &#x7AEF;&#x53E3;&#x53F7; # &#x5173;&#x95ED;&#x67D0;&#x4E2A;&#x7AEF;&#x53E3;
  ufw allow &#x7AEF;&#x53E3;&#x53F7; # &#x5F00;&#x542F;&#x67D0;&#x4E2A;&#x7AEF;&#x53E3;
</code></pre>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="./di-shi-si-zhang-ff1a-flask/di-er-jie-ff1a-flask-restful-cha-jian.html" class="navigation navigation-prev " aria-label="Previous page: 第二节：Flask-Restful插件"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="./di-shi-sizhang-ff1a-redis-jiao-cheng.html" class="navigation navigation-next " aria-label="Next page: 第十六章：redis教程"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="gitbook/app.js"></script>

    
    <script src="gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
